<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书管理系统登录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #2c3e50;
            --accent-color: #3498db;
            --background-color: #f8f9fa;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            background: var(--background-color);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .login-container {
            background: white;
            padding: 2.5rem;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 420px;
            transition: transform 0.3s ease;
        }

        .login-container:hover {
            transform: translateY(-5px);
        }

        .login-header {
            text-align: center;
            margin-bottom: 2rem;
        }

        .login-header h1 {
            color: var(--primary-color);
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-label {
            display: block;
            margin-bottom: 0.5rem;
            color: var(--primary-color);
            font-weight: 500;
        }

        .form-control {
            width: 100%;
            padding: 0.75rem;
            border: 2px solid #e0e0e0;
            border-radius: 6px;
            transition: border-color 0.3s ease;
        }

        .form-control:focus {
            border-color: var(--accent-color);
            box-shadow: none;
        }

        .captcha-wrapper {
            display: flex;
            gap: 1rem;
            align-items: center;
        }

        #captchaImg {
            height: 42px;
            border-radius: 4px;
            cursor: pointer;
            transition: opacity 0.3s ease;
        }

        #captchaImg:hover {
            opacity: 0.9;
        }

        .login-btn {
            width: 100%;
            padding: 0.75rem;
            background: var(--accent-color);
            border: none;
            border-radius: 6px;
            color: white;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        .login-btn:hover {
            background: #2980b9;
        }

        .version-info {
            text-align: center;
            margin-top: 1.5rem;
            color: #95a5a6;
            font-size: 0.9rem;
        }
    </style>
</head>

<body>
<div class="login-container">
    <div class="login-header">
        <h1>系统登录</h1>
        <p>欢迎使用图书管理系统</p>
    </div>

    <form id="loginForm">
        <div class="form-group">
            <label class="form-label" for="username">用户名</label>
            <input type="text"
                   id="username"
                   class="form-control"
                   placeholder="请输入用户名"
                   required>
        </div>

        <div class="form-group">
            <label class="form-label" for="password">密码</label>
            <input type="password"
                   id="password"
                   class="form-control"
                   placeholder="请输入密码"
                   required>
        </div>

        <div class="form-group">
            <label class="form-label" for="captcha">验证码</label>
            <div class="captcha-wrapper">
                <input type="text"
                       id="captcha"
                       class="form-control"
                       placeholder="输入验证码"
                       required>
                <img id="captchaImg"
                     src="/book/captcha"
                     title="点击刷新验证码"
                     onclick="refreshCaptcha()">
            </div>
        </div>

        <button type="button" class="login-btn" onclick="login()">登 录</button>
    </form>

<!--    <div class="version-info">版本号：2.1 S.1</div>-->
</div>

<script src="js/jquery.min.js"></script>
<script>
    function refreshCaptcha() {
        $('#captchaImg').attr('src', '/book/captcha?t=' + Date.now());
    }

    function login() {
        // 保留原有登录逻辑
        $.ajax({
            url: "book/login",
            type: "get",
            data: {
                username: $("#username").val(),
                password: $("#password").val(),
                inputCaptcha: $("#captcha").val()
            },
            success: function(result) {
                if (result.status==200 && result.data == true) {
                    location.href = "book_list.html";
                } else {
                    alert("登录失败，请检查输入信息");
                    // 将三个input框的值都置为空，并刷新验证码
                    $("#captcha").val('');
                    $("#username").val('');
                    $("#password").val('');
                    refreshCaptcha();

                }
            }
        });
    }
    // 输入框回车触发登录
    $('#password, #captcha').keypress(function(e) {
        if (e.which === 13) login();
    });
</script>
</body>
</html>